<template>
  <el-container>
    <el-aside width="200px">
      <img class="logo-white" src="../../public/images/logo-white.png" />
      <Nav />
    </el-aside>
    <el-container>
      <el-header>
        <div class="login-info">
          <el-dropdown>
            <span class="el-dropdown-link">
              <img src="../assets/logo.png" /> <em>{{ username }}</em>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <i class="el-icon-user-solid"></i>
                个人中心
              </el-dropdown-item>
              <el-dropdown-item>
                <i class="el-icon-s-tools"></i>
                系统设置
              </el-dropdown-item>
              <el-dropdown-item>
                <span @click="logout">
                  <i class="el-icon-error"></i>
                  安全退出
                </span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Nav from "./nav.vue";
export default {
  data() {
    return {
      username: "",
    };
  },
  created() {
    var login_data = JSON.parse(localStorage.getItem("loginData") || "{}");
    if (login_data) {
      this.username = login_data.username;
    }
  },
  components: {
    Nav,
  },
  methods: {
    logout() {
      this.$message({
        message: "已退出登录",
        type: "success",
      });
      localStorage.removeItem("loginData");
      this.$router.replace("/login");
    },
  },
};
</script>

<style>
@import url("../../public/css/template.css");
.el-header {
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.login-info {
  width: 200px;
  float: right;
  line-height: 60px;
  padding-top: 10px;
  box-sizing: border-box;
}
.login-info img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  vertical-align: middle;
  float: left;
}
.login-info em {
  float: left;
  margin-left: 10px;
  line-height: 30px;
}

.el-aside {
  background-color: #ff5a3b;
  color: #fff;
  text-align: center;
  min-height: 100vh;
}

.logo-white {
  width: 160px;
  margin-top: 9px;
}
.el-menu-item i {
  color: white !important;
}
.el-main {
  background-color: #e9eef3;
  color: #333;
}
.el-menu-vertical-demo {
  text-align: left;
}
</style>
